package com.woniu.service.impl;

import com.woniu.entity.Orders;
import com.woniu.mapper.OrdersMapper;
import com.woniu.service.OrdersService;
import com.woniu.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrdersServiceImpl implements OrdersService {
    SqlSession sqlSession = MyBatisUtil.getSqlSession();
    OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
    @Override
    public void insertOrders(Orders orders) {
        mapper.insertOrder(orders);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<Orders> selectOrdersByUid(Integer uid) {
        List<Orders> orders = mapper.selectAllOrdersByUid(uid);
        return orders;
    }

    @Override
    public void deleteOrders(Integer uid) {
        mapper.deleteOrders(uid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<Orders> selectOrders() {
        List<Orders> orders = mapper.selectAllOrders();
        return orders;
    }

    @Override
    public void updateOrdersStatus(Integer order_id, Integer status) {
        mapper.updateOrdersStatus(order_id,status);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public Orders selectOrdersByOrderID(Integer order_id) {
        Orders orders = mapper.selectOrdersByOrderID(order_id);
        return orders;
    }

    @Override
    public void updateOrdersTotal(Integer order_id, double price) {
        mapper.updateOrderstotal(order_id,price);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteOrdersByorderId(Integer order_id) {
        mapper.deleteOrdersByorderId(order_id);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<Orders> selectOrdersBStatus(int status) {
        List<Orders> orders = mapper.selectOrdersBStatus(status);
        return orders;
    }

    @Override
    public List<Orders> selectOrdersUidStatus(int uid, int status) {
        List<Orders> orders = mapper.selectOrdersUidStatus(uid, status);
        return orders;
    }


}
